<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Admin\Controller;
use App\Http\Controllers\Api\UploadController;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Storage;

class IndexController extends Controller
{
    //

    //图片上传
   public function upload(Request $request){

       $request->validate([
           'image' => 'image|max:2048',
           'video' => 'file|max:51200|mimes:mp4,ogg,webm', // 只允许MP4, Ogg 或 WebM 格式的视频文件
       ],['image.max' => '图片最大2M',
           'video.max' => '视频最大50M',
           'video.mimes' => '视频后缀不符合',
       ]);

       try {
           if($request->file('image')){

               $image = $request->file('image');
               $filename = date("Y-m-d").'_'.$image->getClientOriginalName();
               Storage::disk('public')->put("images/admin/".$filename, file_get_contents($image));

               return $this->success("/api/v1/image/admin/".$filename.'/');
           }
           if($request->file('video')){

               $image = $request->file('video');
               $filename = date("Y-m-d").'_'.$image->getClientOriginalName();
               Storage::disk('public')->put("video/admin/".$filename, file_get_contents($image));

               return $this->success("/api/v1/video/admin/".$filename);
           }


       }catch (\Exception $exception){

           return false;
       }


   }

}
